﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CN.DBML;
using CN.Commons;
using System.Web.Security;

namespace CityNavigation.Account
{
    public partial class Login : System.Web.UI.Page
    {
        private CityNavigationDataContext dc = new CityNavigationDataContext(System.Configuration.ConfigurationManager.ConnectionStrings["CityNavigationConnectionString"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            int adminCount = (from admin in dc.admins
                          where admin.adname == this.LoginUser.UserName && admin.adpwd == this.LoginUser.Password
                          select admin).Count();
            if (adminCount > 0)
            {
                
            }
            else
            {
                this.LoginUser.FailureText = "用户名或者密码错误，请重新输入！";
                
            }
        }

        protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
        {
            int adminCount = (from admin in dc.admins
                              where admin.adname == this.LoginUser.UserName && admin.adpwd == this.LoginUser.Password
                              select admin).Count();
            if (adminCount > 0)
            {
                this.LoginUser.DestinationPageUrl = "../ImportLines.aspx";
                string a = this.Page.ViewStateUserKey;
                e.Authenticated = true;
                FormsAuthentication.SetAuthCookie(this.LoginUser.UserName, false);
            }
            else
            {
                this.LoginUser.FailureText = "用户名或者密码错误，请重新输入！";
                e.Authenticated = false;
            }
        }
    }
}
